/**
* @author Ashish Gupta
* CVSSP, University of Surrey
* Copyright (c) 2010 Ashish Gupta
* All rights reserved.
*/
/**
 * 
 */
package uk.ac.surrey.agupta.acquisition;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StreamTokenizer;

import uk.ac.surrey.agupta.data.SIFTVector;

/**
 * @author Ashish
 *
 */
public class ReadSIFTData extends ReadFeatureData {

	/**
	 * @throws IOException 
	 * 
	 */
	public ReadSIFTData(String fileName) throws IOException {
		this.setFeatureData(fileName);
	}

	/**
	 * @param fileName
	 * @throws IOException 
	 */
	private void setFeatureData(String fileName) throws IOException {
		File file = new File(fileName);
		Reader fr = new FileReader(file);
		StreamTokenizer st = new StreamTokenizer(fr);
		st.parseNumbers();
		st.nextToken();
		int numFeatureVectors = (int) st.nval;
		st.nextToken();
		int numDescriptorDimensions = (int) st.nval;
		for(int i=0;i<numFeatureVectors;i++){
			SIFTVector fv = new SIFTVector(numDescriptorDimensions);
			for(int j=0;j<4;j++){
				st.nextToken();
			}
			for(int j=0;j<numDescriptorDimensions;j++){
				st.nextToken();
				int feature = (int) st.nval;
				fv.setFeatureVector(feature);
			}
			this.setFeatureData(fv);
		}
	}

}
